package com.tao.erp.menu.action;


import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tao.erp.emp.pojo.Emp;
import com.tao.erp.menu.pojo.Menu;
import com.tao.erp.menu.service.MenuService;

@Controller
@RequestMapping("/menu")
public class MenuAction {


	
	@Autowired
	private MenuService menuService;
	
	@RequestMapping("/selectMenu.action")
	@ResponseBody
	public Menu selectMenu(HttpServletRequest request){
		Emp emp = (Emp) request.getSession().getAttribute("sessionEmp");
		List<Menu> list = menuService.selectMenuListByEmpId(emp.getUuid());
		Menu menu = menuService.selectMenuByPid(0);
		List<Menu> pList=new ArrayList<Menu>();		
		for (Menu m : list) {
			if(menu.getUuid().equals(m.getPuuid())){
				List<Menu> cList=new ArrayList<Menu>();
				for (Menu mm : list) {
					if(m.getUuid().equals(mm.getPuuid())){
						cList.add(mm);
					}
				}
				m.setList(cList);
				pList.add(m);
			}
		}
		menu.setList(pList);
		return menu;
	}
}
